// 输出 3[k]2[mn]  进行解压
//输入一行字符串, f3@d5a8, 转为数字
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let str;
const left = "["
const right = "]"
rl.on("line", (line)=>{
    if(str === undefined) {
        str = line.trim()
        getResult(str);
        // clear
        str = undefined
    }
})

function getResult(str) {
    let stack = []
    for (const char of str) {
        if(char !== right) {
            stack.push(char)
        } else {
            // 开始处理 3[k]2[mn]
            let str = ""
            while(stack.length) {
                let pop = stack.pop();
                if(pop === left) {
                    break;
                } else {
                    str = pop + str; // 字母
                }
            }

            // 开始处理数字
            let numStr = stack.pop() + ""
            while(stack.length) {
                let char = stack.at(-1)
                if(isNaN(char)) {
                    break
                } else {
                    numStr = stack.pop() + numStr
                }
            }
            let tempStr = str.repeat(Number(numStr));
            stack.push(tempStr)
        }

    }

    console.log(stack.join(""))
    console.log(stack.join("").length)
}